import type { App } from "vue";
import { createRouter, createWebHashHistory, type RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layouts/index.vue");
// 公共
export const gongg = [
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/401",
    component: () => import("@/views/error/401.vue"),
    meta: { hidden: true },
  },
  {
    path: "/404",
    component: () => import("@/views/error/404.vue"),
    meta: { hidden: true },
  },
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },
];
// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/Workhourinquiry",
    meta: {
      title: "人员管理",
      icon: "Frame",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "Workhourinquiry",
        component: () => import("@/views/Workhourinquiry/index.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "home1",
        meta: {
          title: "工时查询",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "detail",
        component: () => import("@/views/Workhourinquiry/detail.vue"),
        name: "detail",
        meta: {
          hidden: true,
          title: "详情",
          alwaysShow: false,
          affix: true,
          keepAlive: true,
        },
      },

      {
        path: "varianceAnalysis",
        component: () => import("@/views/Workhourinquiry/varianceAnalysis.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "varianceAnalysis",
        meta: {
          title: "差异分析",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "ProjectSummary",
        component: () => import("@/views/Workhourinquiry/ProjectSummary.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "Frame(1)",
        meta: {
          title: "项目汇总",
          affix: true,
          keepAlive: true,
        },
      },

      {
        path: "HolidaySummary",
        component: () => import("@/views/Workhourinquiry/HolidaySummary.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "HolidaySummary",
        meta: {
          title: "假期汇总",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "jiaban",
        component: () => import("@/views/Workhourinquiry/jiaban.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "jiaban",
        meta: {
          title: "项目及加班小时",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "jiabanjisuan",
        component: () => import("@/views/Workhourinquiry/jiabanjisuan.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "jiabanjisuan",
        meta: {
          title: "加班费计算",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "liyonglv",
        component: () => import("@/views/Workhourinquiry/liyonglv.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "liyonglv",
        meta: {
          title: "利用率",
          affix: true,
          keepAlive: true,
        },
      },

      {
        path: "profile",
        name: "Profile",
        component: () => import("@/views/profile/index.vue"),
        meta: { title: "个人中心", icon: "user", hidden: true },
      },
      {
        path: "my-notice",
        name: "MyNotice",
        component: () => import("@/views/system/notice/components/MyNotice.vue"),
        meta: { title: "我的通知", icon: "user", hidden: true },
      },
      {
        path: "/detail/:id(\\d+)",
        name: "DemoDetail",
        component: () => import("@/views/demo/detail.vue"),
        meta: { title: "详情页缓存", icon: "user", hidden: true, keepAlive: true },
      },
    ],
  },
  {
    path: "/ProjectManagement",
    component: Layout,
    redirect: "/ProjectOverallManagement",
    name: "/ProjectManagement",
    meta: {
      title: "项目管理",
      icon: "xiangmu",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "ProjectOverallManagement",
        component: () => import("@/views/ProjectManagement/ProjectOverallManagement.vue"),
        name: "ProjectOverallManagement",
        meta: {
          title: "项目总体工时",
          affix: true,
          keepAlive: true,
        },
      },

      {
        path: "ProjectPersonnelWorkingHours",
        component: () => import("@/views/ProjectManagement/ProjectPersonnelWorkingHours.vue"),
        name: "ProjectPersonnelWorkingHours",
        meta: {
          title: "项目人员工时",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "WorkContentWorkingHours",
        component: () => import("@/views/ProjectManagement/WorkContentWorkingHours.vue"),
        name: "WorkContentWorkingHours",
        meta: {
          title: "工作内容工时",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "AuditHours",
        component: () => import("@/views/ProjectManagement/AuditHours.vue"),
        name: "AuditHours",
        meta: {
          title: "审计工时",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "ProjectCost",
        component: () => import("@/views/ProjectManagement/ProjectCost.vue"),
        name: "ProjectCost",
        meta: {
          title: "项目成本",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/rojectEstablishmentManagement",
    component: Layout,
    redirect: "/rojectEstablishmentManagement",
    name: "/HolidayManagement",
    meta: {
      title: "立项管理",
      icon: "lixiangicon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "HolidayManagement",
        component: () => import("@/views/rojectEstablishmentManagement/HolidayManagement.vue"),
        name: "HolidayManagement",
        meta: {
          title: "假期管理",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "PublicAffairs",
        component: () => import("@/views/rojectEstablishmentManagement/PublicAffairs.vue"),
        name: "PublicAffairs",
        meta: {
          title: "公共事项管理",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "xmgl",
        component: () => import("@/views/rojectEstablishmentManagement/xmgl.vue"),
        name: "xmgl",
        meta: {
          title: "项目管理",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "WorkContentManagement",
        component: () => import("@/views/rojectEstablishmentManagement/WorkContentManagement.vue"),
        name: "WorkContentManagement",
        meta: {
          title: "工作内容管理",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/EmployeeManagement",
    component: Layout,
    redirect: "/EmployeeManagementindex",
    name: "/EmployeeManagement",
    meta: {
      title: "员工管理",
      icon: "ygongicon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "EmployeeManagementindex",
        component: () => import("@/views/EmployeeManagement/index.vue"),
        name: "EmployeeManagementindex",
        meta: {
          title: "员工管理",
          icon: "ygongicon",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/PermissionManagement",
    component: Layout,
    redirect: "/RoleManagement",
    name: "/PermissionManagement",
    meta: {
      title: "权限管理",
      icon: "quanxianicon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "RoleManagement",
        component: () => import("@/views/PermissionManagement/RoleManagement.vue"),
        name: "RoleManagement",
        meta: {
          title: "角色管理",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "AdministratorManagement",
        component: () => import("@/views/PermissionManagement/AdministratorManagement.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "AdministratorManagement",
        meta: {
          title: "管理员管理",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/SystemConfiguration",
    component: Layout,
    redirect: "/BasicSettings",
    name: "/SystemConfiguration",
    meta: {
      title: "系统配置",
      icon: "seticon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "BasicSettings",
        component: () => import("@/views/SystemConfiguration/BasicSettings.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "BasicSettings",
        meta: {
          title: "基础设置",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "SystemSettings",
        component: () => import("@/views/SystemConfiguration/SystemSettings.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "SystemSettings",
        meta: {
          title: "系统设置",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
];
// 员工端
export const staff = [
  {
    path: "/",
    component: Layout,
    redirect: "/manHour",
    name: "/",
    meta: {
      title: "工时管理",
      icon: "gongshiguanlicion",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "manHour",
        component: () => import("@/views/staff/Workinghourinquiry/manHour.vue"),
        name: "manHour",
        meta: {
          title: "工时管理",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "manHourdetial",
        component: () => import("@/views/staff/Workinghourinquiry/manHourdetial.vue"),
        name: "manHourdetial",
        meta: {
          hidden: true,
          title: "详情",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "CreateIndependently",
        component: () => import("@/views/staff/Workinghourinquiry/CreateIndependently.vue"),
        name: "CreateIndependently",
        meta: {
          hidden: true,
          title: "独立创建",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "lookchayi",
        component: () => import("@/views/staff/Workinghourinquiry/lookchayi.vue"),
        name: "lookchayi",
        meta: {
          hidden: true,
          title: "查看差异列表",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "usegsmb",
        component: () => import("@/views/staff/Workinghourinquiry/usegsmb.vue"),
        name: "usegsmb",
        meta: {
          hidden: true,
          title: "使用工时模版",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/chayifenxi",
    component: Layout,
    redirect: "/chayifenxiindex",
    name: "/chayifenxi",
    meta: {
      title: "差异分析",
      icon: "chayifenxiicon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "chayifenxiindex",
        component: () => import("@/views/chayifenxi/chayifenxiindex.vue"),
        name: "chayifenxiindex",
        meta: {
          title: "差异分析",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/xmhz",
    component: Layout,
    redirect: "/xmhzindex",
    name: "/xmhz",
    meta: {
      title: "项目汇总",
      icon: "xmhuizongicon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "xmhzindex",
        component: () => import("@/views/staff/xmhz/xmhzindex.vue"),
        name: "xmhzindex",
        meta: {
          title: "项目汇总",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/jiaqimx",
    component: Layout,
    redirect: "/jiaqimxindex",
    name: "/jiaqimx",
    meta: {
      title: "假期明细",
      icon: "jiaqimingxiicon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "jiaqimxindex",
        component: () => import("@/views/staff/jiaqimx/jiaqimxindex.vue"),
        name: "jiaqimxindex",
        meta: {
          title: "假期明细",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/SystemConfiguration",
    component: Layout,
    redirect: "/BasicSettings",
    name: "/SystemSettings",
    meta: {
      title: "系统配置",
      icon: "seticon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "SystemSettings",
        component: () => import("@/views/SystemConfiguration/SystemSettings.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "SystemSettings",
        meta: {
          title: "系统设置",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
];
const review = [
  {
    path: "/",
    component: Layout,
    redirect: "/reviewindex",
    name: "/",
    meta: {
      title: "审核管理",
      icon: "gongshiguanlicion",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "reviewindex",
        component: () => import("@/views/review/reviewindex.vue"),
        name: "reviewindex",
        meta: {
          title: "审核管理",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/staff",
    component: Layout,
    redirect: "/manHour",
    name: "/staff",
    meta: {
      title: "工时管理",
      icon: "gongshiguanlicion",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "manHour",
        component: () => import("@/views/staff/Workinghourinquiry/manHour.vue"),
        name: "manHour",
        meta: {
          title: "工时管理",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "manHourdetial",
        component: () => import("@/views/staff/Workinghourinquiry/manHourdetial.vue"),
        name: "manHourdetial",
        meta: {
          hidden: true,
          title: "详情",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "CreateIndependently",
        component: () => import("@/views/staff/Workinghourinquiry/CreateIndependently.vue"),
        name: "CreateIndependently",
        meta: {
          hidden: true,
          title: "独立创建",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "lookchayi",
        component: () => import("@/views/staff/Workinghourinquiry/lookchayi.vue"),
        name: "lookchayi",
        meta: {
          hidden: true,
          title: "查看差异列表",
          affix: true,
          keepAlive: true,
        },
      },
      {
        path: "usegsmb",
        component: () => import("@/views/staff/Workinghourinquiry/usegsmb.vue"),
        name: "usegsmb",
        meta: {
          hidden: true,
          title: "使用工时模版",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/chayifenxi",
    component: Layout,
    redirect: "/chayifenxiindex",
    name: "/chayifenxi",
    meta: {
      title: "差异分析",
      icon: "chayifenxiicon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "chayifenxiindex",
        component: () => import("@/views/chayifenxi/chayifenxiindex.vue"),
        name: "chayifenxiindex",
        meta: {
          title: "差异分析",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/xmhz",
    component: Layout,
    redirect: "/xmhzindex",
    name: "/xmhz",
    meta: {
      title: "项目汇总",
      icon: "xmhuizongicon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "xmhzindex",
        component: () => import("@/views/staff/xmhz/xmhzindex.vue"),
        name: "xmhzindex",
        meta: {
          title: "项目汇总",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/jiaqimx",
    component: Layout,
    redirect: "/jiaqimxindex",
    name: "/jiaqimx",
    meta: {
      title: "假期明细",
      icon: "jiaqimingxiicon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "jiaqimxindex",
        component: () => import("@/views/staff/jiaqimx/jiaqimxindex.vue"),
        name: "jiaqimxindex",
        meta: {
          title: "假期明细",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
  {
    path: "/SystemConfiguration",
    component: Layout,
    redirect: "/BasicSettings",
    name: "/SystemSettings",
    meta: {
      title: "系统配置",
      icon: "seticon",
      affix: true,
      keepAlive: true,
    },
    children: [
      {
        path: "SystemSettings",
        component: () => import("@/views/SystemConfiguration/SystemSettings.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "SystemSettings",
        meta: {
          title: "系统设置",
          icon: "homepage",
          affix: true,
          keepAlive: true,
        },
      },
    ],
  },
];

if (import.meta.env.VITE_APP_STAFF == "true") {
  gongg.unshift(...staff);
} else if (import.meta.env.VITE_APP_STAFF == "review") {
  gongg.unshift(...review);
} else {
  gongg.unshift(...constantRoutes);
}
console.log(gongg, "gongggongggongg");

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: gongg,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 全局注册 router
export function setupRouter(app: App<Element>) {
  app.use(router);
}

export default router;
